<?php
/**
 * Created by JetBrains PhpStorm.
 * User: vtrinh
 * Date: 10/22/11
 * Time: 1:20 PM
 * To change this template use File | Settings | File Templates.
 */
require 'global.php';

$facebook = new Facebook(array('appId'  => '283217508366280', 'secret' => '81eb81cc31f65789457c7b86eb0dc0f0'));
$userId = $facebook->getUser();

$clientCode = REQUEST('code');
if($userId && $clientCode){
	if(isOriginFacebook()){
		redirect('http://apps.facebook.com/proto_personal/labs/mallsim_server/');
	}
}

if(!$userId){
	if(isOriginFacebook()){
		oAuthRedirectForFacebook();
	} else {
		oAuthRedirectForWebsite();
	}
} else {
	$clientFilesPath = 'http://vinhtrinh.org/labs/mallsim/bin-debug/';
	include 'gameTemplate.php';
}

//qd($_REQUEST);
//$userId = $facebook->getUser();
//qd($userId);
//if($userId == 0){
//	$clientCode = REQUEST('code');
//	if($clientCode == null){
//		qd("REDIRECTING");
//		redirectForClientCode();
//	}
//
//	$accessToken = getAccessToken($clientCode);
//	$facebook->setAccessToken($accessToken);
//}
//
//$facebook->getUser();
//qd($userId);
//
//$authKey = 'auth_'.$userId;
//$authBlob['accessToken'] = $facebook->getAccessToken();
//if(!empty($clientCode)){
//	$authBlob['clientCode'] = $clientCode;
//}

//writeToPersistence($authKey, $authBlob);

